|
|
|
|
|
|
|
Use the HTML <SCRIPT> tag with the RUNAT=SERVER option. |
|
|
|
|
|
|
|
|
Use <% and %> to mark the beginning and end of the server-side script. This syntax is shorter and is the one I recommend. |
|
|
|
|
|
|
|
|
However you decide to mark the script, make sure to place it within the script delimiters, as in the following examples: |
|
|
|
|
|
|
|
|
<SCRIPT LANGUAGE="VBSCRIPT" RUNAT="SERVER">
Dim i
For i = 1 to 10
Response.Write ("This is line " & i & "<BR>")
Next
</SCRIPT> |
|
|
|
|
|
|
|
|
The same code can also be marked with the shorter tags: |
|
|
|
|
|
|
|
|
<%
Dim i
For i = 1 to 10
Response.Write ("This is line " & i & "<BR>")
Next
%> |
|
|
|
|
|
|
|
|
Notice that you do not need to specify a scripting language in the second example. This is because the default scripting language for ASP files is VBScript. However, the default scripting language is a configurable option, so you might want to place the following line at the beginning of each of your ASP files: |
|
|
|
|
|
|
|
|
<%@ LANGUAGE="VBSCRIPT" %> |
|
|
|
|
|
|
|
|
This line is a directive to the script engine that sets the default language to VBScript for the current ASP page. Although your script tags can be placed anywhere in the ASP file, there are a few restrictions: |
|
|
|
|
|
|
|
|
Certain directives and options, like the previous line of code and the Option Explicit statement, must be placed at the very beginning of the file, even before the <HTML> tag. |
|
|
|
|
|
|
|
|
If your page is used to redirect the user to another side, you cannot send any HTML back to the browser. (You get a demonstration of this in an upcoming section.) |
|
|
|
|
|
|
|
|
You cannot enter straight HTML inside the script tags, unless you use the Response.Write statement. |
|
|
|
|
|
|
|
|
Also, keep in mind that the code you are entering is VBScript, not the full-featured Visual Basic language. There are some differences and limitations, as discussed in Chapter 30, "Using VBScript." |
|
|
|
|
|
|
|
|
See "Introduction to VBScript," p. 666 |
|
|
|
|
|
|
|
|
See "The VBScript Language," p. 673 |
|
|
|
|
|
|
|
|
Simple but Dynamic Web Pages |
|
|
|
|
|
|
|
|
Now that you know the basics, let's write another simple ASP file. At my office there is a computer named cdtower which, as you might have guessed, is attached to a tower of CD-ROM |
|
|
|
|
|